package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class ReturnOperation implements  IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("返还图书");
        System.out.println("返还书籍名称");
        Scanner scanner=new Scanner(System.in);
        String name=scanner.nextLine();
        int cur=bookList.getUsedSize();
        for(int i=0;i<cur;i++)
        {
            Book book=bookList.getBook(i);
            if(book.getName().equals(name))
            {if(book.isBorrowed())
            {
                book.setBorrowed(false);
                System.out.println("成功退还");
                System.out.println(book);
                return;
            }
            else
            {
                System.out.println("该书已被退还");
                return;
            }

            }
        }
        System.out.println("输入书籍信息错误");
        return;

    }
}